package com.xiaoshuidi.cloud.module.finance.api.finance;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.module.finance.dal.dataobject.finance.FinanceAccountWithdrawDO;
import com.xiaoshuidi.cloud.module.finance.dal.mysql.finance.FinanceAccountWithdrawMapper;
import com.xiaoshuidi.cloud.module.finance.enums.finance.FinanceAccountWithdrawResultEnum;
import com.xiaoshuidi.cloud.module.finance.enums.finance.FinanceCustomerTypeEnum;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@RestController
public class FinanceAccountWithdrawImpl implements FinanceAccountWithdrawApi {

    @Resource
    private FinanceAccountWithdrawMapper financeAccountWithdrawMapper;


    @Override
    public CommonResult<Boolean> withdrawalRoomVerification(String phone, Long companyId, Long roomId) {
        LambdaQueryWrapper<FinanceAccountWithdrawDO> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(FinanceAccountWithdrawDO::getCompanyId, companyId)
                .eq(FinanceAccountWithdrawDO::getRoomId, roomId)
                .eq(FinanceAccountWithdrawDO::getResult, FinanceAccountWithdrawResultEnum.PENDING.name())
                .eq(FinanceAccountWithdrawDO::getCustType, FinanceCustomerTypeEnum.ROOM.name())
                .and(a -> a.eq(FinanceAccountWithdrawDO::getApplyMemberPhone, phone)
                        .or()
                        .eq(FinanceAccountWithdrawDO::getReviewMemberPhone, phone)
                );
        Long aLong = financeAccountWithdrawMapper.selectCount(queryWrapper);
        return CommonResult.success(aLong <= 0);
    }
}
